/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.12
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   if条件指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "ifinstructionview.h"
#include "ui_ifinstructionview.h"
#include "../../programView/programview.h"
#include "ifconditiondialog.h"

IfInstructionView::IfInstructionView(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::IfInstructionView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);

//    for(int i = 1; i <= 200; i++)
//    {
//        ui->LBLData_comboBox->addItem(QString::number(i));
//    }
//    ui->LBLData_comboBox->setMaxVisibleItems(10);

    conditionDialog=new IfConditionDialog(styleId,this);
    conditionDialog->hide();
    connect(conditionDialog, SIGNAL(sendCondition_signal(QString)), this, SLOT(sendCondition_slot(QString)));

}

void IfInstructionView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        ui->save_Btn->setGeometry(360,350,70,40);
        break;
    default:
        break;
    }
}

void IfInstructionView::sendCondition_slot(QString condition)
{
    ui->condition_lineEdit->setText(condition);
}

void IfInstructionView::setProgromFileName(QString fileName)
{
    ui->callPro_lineEdit->setText(fileName);
}

void IfInstructionView::updateView()
{
    if(0 == dealWithFlag)
    {
        ui->JMP_radioButton->setChecked(true);
    }
    else if(1 == dealWithFlag)
    {
        ui->CALL_radioButton->setChecked(true);
    }

    ui->lineEdit_labelStr->setText(labelStr);
//    ui->LBLData_comboBox->setCurrentIndex(lblIndex - 1);
    ui->LBLDataType_comboBox->setCurrentIndex(lblDataType);
    ui->callPro_lineEdit->setText(callProgram);
    ui->condition_lineEdit->setText(ifCondition);
    ui->note_lineEdit->setText(note);
}

void IfInstructionView::getInput()
{
    labelStr=ui->lineEdit_labelStr->text();
//    lblIndex = ui->LBLData_comboBox->currentIndex() + 1;
    lblDataType = ui->LBLDataType_comboBox->currentIndex();
    ifCondition = ui->condition_lineEdit->text();
    callProgram = ui->callPro_lineEdit->text();

    note = ui->note_lineEdit->text();
}

void IfInstructionView::on_JMP_radioButton_clicked()
{
    emit selectJmp();
}

void IfInstructionView::on_CALL_radioButton_clicked()
{
    emit selectCall();
}

void IfInstructionView::on_browse_Btn_clicked()
{
    emit browseCallProgram(callLocation);

    ui->callPro_lineEdit->setText(callProgram);
}

void IfInstructionView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit cleanNote();
}


void IfInstructionView::on_save_Btn_clicked()
{
    getInput();

    emit finishEditInstruction();
    emit saveInstruction(ifInstruction);
}

void IfInstructionView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/ifViewEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
}

void IfInstructionView::on_button_help_clicked()
{
    conditionDialog->show();
}
